package com.yyy.gui.pannel;

import com.yyy.gui.page.SpendPage;
import com.yyy.service.SpendService;
import com.yyy.util.CenterPanel;
import com.yyy.util.CircleProgressBar;
import com.yyy.util.ColorUtil;
import com.yyy.util.GUIUtil;

import javax.swing.*;
import java.awt.*;

/**
 * @Author：yyy
 * @Package：com.yyy.gui.pannel
 * @Project：HuTuBiill
 * @name：SpendPanel
 * @Date：2024/11/7 23:38
 * @Filename：SpendPanel
 */
public class SpendPanel extends WorkingPanel{
    //单例模式
    public static SpendPanel instance=new SpendPanel();
    public JLabel lMonthSpend=new JLabel("本月消费");
    public JLabel lTodaySpend=new JLabel("本日消费");
    public JLabel lAvgSpendPerDay=new JLabel("日均消费");
    public JLabel lMonthLeft=new JLabel("本月剩余");
    public JLabel lDayAvgAvaiable=new JLabel("日均可用");
    public JLabel lMonthLeftDay=new JLabel("距离月末");

    public JLabel vMonthSpend=new JLabel("￥2300");
    public JLabel vTodaySpend=new JLabel("￥100");
    public JLabel vAvgSendPerDay=new JLabel("￥80");
    public JLabel vMonthLeft=new JLabel("￥700");
    public JLabel vDayAvgAvaiable=new JLabel("100");
    public JLabel vMonthLeftDay=new JLabel("7");
    public CircleProgressBar bar;

    public SpendPanel(){
        this.setLayout(new BorderLayout());
        bar=new CircleProgressBar();
        //设置消费分类百分图背景色
        bar.setBackgroundColor(ColorUtil.blueColor);
        GUIUtil.setColor(ColorUtil.grayColor,lMonthSpend,lTodaySpend,lAvgSpendPerDay,lMonthLeft,lDayAvgAvaiable,lMonthLeftDay,
                vAvgSendPerDay,vMonthLeft,vDayAvgAvaiable,vMonthLeftDay);
        GUIUtil.setColor(ColorUtil.blueColor,vMonthSpend,vTodaySpend);
        vMonthSpend.setFont(new Font("微软雅黑",Font.BOLD,23));
        vTodaySpend.setFont(new Font("微软雅黑",Font.BOLD,23));
        this.add(center(),BorderLayout.CENTER);
        this.add(south(),BorderLayout.SOUTH);

    }
    private JPanel center(){
        JPanel p=new JPanel();
        p.setLayout(new BorderLayout());
        p.add(west(),BorderLayout.WEST);
        p.add(east());
        return p;
    }
    private Component west(){
        JPanel p=new JPanel();
        p.setLayout(new GridLayout(4,1));
        p.add(lMonthSpend);
        p.add(vMonthSpend);
        p.add(lTodaySpend);
        p.add(vTodaySpend);
        return p;
    }

    private Component east(){
        return bar;
    }
    private JPanel south(){
        JPanel p=new JPanel();
        p.setLayout(new GridLayout(2,4));
        p.add(lAvgSpendPerDay);
        p.add(lMonthLeft);
        p.add(lDayAvgAvaiable);
        p.add(lMonthLeftDay);
        p.add(vAvgSendPerDay);
        p.add(vMonthLeft);
        p.add(vDayAvgAvaiable);
        p.add(vMonthLeftDay);
        return p;

    }



    @Override
    public void addListener() {

    }

    @Override
    public void updateData() {
        SpendPage spend=new SpendService().getSpendPage();
        vMonthSpend.setText(spend.monthSpend);
        vTodaySpend.setText(spend.todaySpend);
        vAvgSendPerDay.setText(spend.avgSpendPerDay);
        vMonthLeft.setText(spend.monthAvailable);
        vDayAvgAvaiable.setText(spend.dayAvgAvailable);
        vMonthLeftDay.setText(spend.monthLeftDay);
        bar.setProgress(spend.usePercentage);
        if(spend.isOverSpend){
            vMonthLeft.setForeground(ColorUtil.warningColor);
            vMonthSpend.setForeground(ColorUtil.warningColor);
            vTodaySpend.setForeground(ColorUtil.warningColor);
        }else {
            vMonthLeft.setForeground(ColorUtil.grayColor);
            vMonthSpend.setForeground(ColorUtil.blueColor);
            vTodaySpend.setForeground(ColorUtil.blueColor);
        }
        bar.setForegroundColor(ColorUtil.getByPercentage(spend.usePercentage));
        addListener();

    }



}
